package thread;

/**
 * Created with IntelliJ IDEA.
 *
 * @ Title
 * @ Description:
 * @ Auther: 赵彦博
 * @ Date: 2022-12-02
 * @ Time: 18:48
 */
@SuppressWarnings({"all"})
public class Demo10 {
    private static boolean isQuit = false;

    public static void main(String[] args) {
        Thread t = new Thread(() -> {
           while (!isQuit) {
               System.out.println("hello thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        });
        t.start();

        // 只要把这个 isQuit 设为true，此时这个循环就退出了，进一步的run就执行完了，再进一步就是线程执行结束了
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        isQuit = true;
        System.out.println("终止 t 线程！");

    }
}
